﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Manager_AddAdmin : System.Web.UI.Page
{
    CommonClass ccobj = new CommonClass();
    DBClass dbobj = new DBClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            bindDepart();
    }
    protected void bindDepart()
    {

        DataTable dstable = dbobj.GetDataSet("select * from Department", "tabdepartment");

        DropDownList1.DataSource = dstable.DefaultView;
        DropDownList1.DataTextField = dstable.Columns[1].ToString();
        DropDownList1.DataValueField = dstable.Columns[0].ToString();
        DropDownList1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string strsql = "select * from Admin where AdminID='" + TextBox1.Text.Trim() + "'";
        DataTable dstable = dbobj.GetDataSet(strsql, "tabadmin");
        if (dstable.Rows.Count > 0)
        {
            Response.Write(ccobj.MessageBoxPage("该用户已注册！"));
        }
        else
        {
            string departmentid = dbobj.ExecScalar("select DepartmentID from Department where DepartmentName='" + DropDownList1.SelectedItem.Text.ToString() + "'");
            int t = (CheckBox1.Checked ? 1 : 0);
            string strinsert = "insert into Admin (AdminID,AdminName,PassWord,DepartmentID,IsTestMan) values('" + TextBox1.Text.Trim() + "','" + TextBox2.Text.Trim() + "','" + TextBox1.Text.Trim() + "','" + departmentid + "'," + t + ")";
            dbobj.ExecNonQuery(strinsert);
            Response.Write(ccobj.MessageBox("添加成功！"));
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        CheckBox1.Checked = false;
    }
}